<template>
  <!-- 模板内容：只能有一个div  -->
  <div>
    <div class="box">
      <h2>新秀菜谱</h2>
      <div class="content_btn">
        <button class="prev" @click="prev" ref="prev">&lt;</button>
        <button class="next" @click="next" ref="next">&gt;</button>
      </div>
      <div class="content_paging" ref="content">
        <div v-for="(item, index) in list" :key="index">
          <img :src="item.img" alt="" />
          <h5>{{ item.title }}</h5>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import axios from "axios";
export default {
  name: "Paging",
  created() {
    this.fn_a();
  },
  data() {
    return {
      count: 0,
      list: [],
    };
  },
  methods: {
    async fn_a() {
      let { data } = await axios.get(
        "https://mock.presstime.cn/mock/61bbe55090bfb20016179195/broducttest/shoppingcard"
      );
      (this.list = data.content_menu_img), console.log(data.content_menu_img);
    },
    prev() {
      if (this.count == 0) {
        this.count = 0;
      } else {
        this.$refs.prev.disabled = false;
        this.count--;
        this.$refs.content.style.left = -500 * this.count + "px";
      }
    },
    next() {
      if (this.count >= 4) {
        this.count = 4;
      } else {
        this.$refs.next.disabled = false;
        this.count++;
        this.$refs.content.style.left = -500 * this.count + "px";
      }
    },
  },
};
</script>

<style lang="less" scoped>
/* css样式 */
.box {
  width: 500px;
  height: 170px;
  //   background: red;
  overflow: hidden;
  position: relative;
  .content_btn{
      float: right;
      margin-right: 20px;
  }
  .prev {
    width: 40px;
    height: 30px;
    border: none;
  }
  .next {
    width: 40px;
    margin-left: 10px;
    height: 30px;
    border: none;

  }
  h2 {
    margin: 5px;
    font-size: 20px;
    color: #c0ae7d;
    display: inline-block;
  }
  .content_paging {
    width: 50000px;
    align-items: center;
    // margin-left: 10px;
    position: absolute;
    left: 0;
    transition: 1s;
    div {
      margin-left: 15px;
      text-align: center;
      margin-top: 5px;
      height: 100px;
      float: left;
      //   background: darkblue;
      h5 {
        margin-top: 6px;
        font-size: 14px;
        font-weight: normal;
        color: #000;
      }
      img {
        width: 150px;
        height: 90px;
      }
    }
  }
}
</style>